package com.book.service.io;

import java.io.IOException;
import java.io.InputStream;

import org.apache.log4j.Logger;

public class EncryptedInputStream extends InputStream {
	private static final Logger logger = Logger.getLogger(EncryptedInputStream.class);

	private InputStream inputStream;

	public EncryptedInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	@Override
	public int read() throws IOException {
		logger.debug("read()");
		return ~inputStream.read();
	}

	@Override
	public int read(byte[] b) throws IOException {
		int size = inputStream.read(b);
		for (int i = 0; i < b.length; i++) {
			b[i] = (byte) ~b[i];
		}
		return size;
	}

}
